#pragma once

#include <string>
#include <QSettings>
#include <map>

#include "const.h"

class Config : public QObject {
	Q_OBJECT

	public:
		enum Fields { Database, Overwrite, ShowHelp, StopProcessingOn, SilentOrder };

		static void init(QString path, QObject *parent = 0);

		static Config& Instance() {
			static Config conf;
			return conf;
		}

		std::string database() const;

		void setDatabase(std::string path);

		bool overwrite() const;

		void setOverwrite(bool value);

		bool showHelp() const;

		void setShowHelp(bool value);

		ProcessingError::ProcessingErrorType stopProcessingOn() const;

		void setStopProcessingOn(ProcessingError::ProcessingErrorType value);

		bool haltOnDownloadError() const { return (stopProcessingOn() == ProcessingError::Download or stopProcessingOn() == ProcessingError::Any); }

		bool haltOnInstallError() const { return (stopProcessingOn() == ProcessingError::Install or stopProcessingOn() == ProcessingError::Any); }

		bool silentFirst() const { return silent() == SilentOrder::First; }

		SilentOrder::SilentOrderTypes silent() const { return static_cast<SilentOrder::SilentOrderTypes>(settings->value(lookup[Config::SilentOrder], SilentOrder::First).toInt()); }
		void setSilent(SilentOrder::SilentOrderTypes order);


	public slots:
		void sync();

	private:

		Config() { }
		Config(Config const&);
		Config& operator= (Config const&);
		~Config() { }

		static QSettings *settings;
		static std::map<int, QString> lookup;

	// FIXME find why signal from singleton doesn't work
// 	signals:
// 		void databaseLocationChanged();
};

#define CONFIG Config::Instance()

